package com.example.kotlindemo.协程;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;

public class Demo {
    public static void main(String[] args) {
        CompletableFuture<Double> cf  =  CompletableFuture.supplyAsync(Demo::fetchDemo); //耗时任务
        cf.thenAccept(aDouble -> {
            //todo
        });

        cf.exceptionally(throwable -> {
            throwable.printStackTrace();
            return null;
        });
    }


    static Double fetchDemo(){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}
